/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cadi.aux;

import java.applet.AudioClip;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

/**
 *
 * @author Vercetti
 */
public class Clickable extends JLabel {
    
    private boolean goal;
    private MouseAdapter event;
    private int value;
    private AudioClip voice;
    
    public Clickable(ImageIcon icon){
        this.setIcon(icon);
        event = new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent evt){
                if (goal){
                    voice = java.applet.Applet.newAudioClip(getClass().getResource("/resources/bien.wav"));
                    voice.play();
                    JOptionPane.showMessageDialog(null, "¡Bien Hecho!", "¡Bien Hecho!", JOptionPane.INFORMATION_MESSAGE, new ImageIcon(getClass().getResource("/resources/right.png")));
                    
                    goal = false;
                    
                }else{
                    voice = java.applet.Applet.newAudioClip(getClass().getResource("/resources/mal.wav"));
                  voice.play();
                  JOptionPane.showMessageDialog(null, "Intenta de nuevo", "Intenta de nuevo", JOptionPane.INFORMATION_MESSAGE, new ImageIcon(getClass().getResource("/resources/wrong.png"))); 
                  
                }
                
            }};
        this.addMouseListener(event);
    }
    
    
    public void setGoal(boolean goal){
        this.goal = goal;
        
    }
    
    public void setEvent(int number){
        this.value = number;
        this.removeMouseListener(event);
        event = new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent evt){
                if (goal){ 
                    switch(value){
                        case 0:
                            voice = java.applet.Applet.newAudioClip(getClass().getResource("/resources/bien.wav"));
                            voice.play();
                            JOptionPane.showMessageDialog(null, "¡Bien Hecho!", "¡Bien Hecho!", JOptionPane.INFORMATION_MESSAGE, new ImageIcon(getClass().getResource("/resources/right.png")));
                            break;
                        case 20:
                            voice = java.applet.Applet.newAudioClip(getClass().getResource("/resources/bien.wav"));
                            voice.play();
                            JOptionPane.showMessageDialog(null, "¡Bien Hecho!", "¡Bien Hecho!", JOptionPane.INFORMATION_MESSAGE, new ImageIcon(getClass().getResource("/resources/right20.png")));
                            break;
                        case 50:
                            voice = java.applet.Applet.newAudioClip(getClass().getResource("/resources/bien.wav"));
                            voice.play();
                            JOptionPane.showMessageDialog(null, "¡Bien Hecho!", "¡Bien Hecho!", JOptionPane.INFORMATION_MESSAGE, new ImageIcon(getClass().getResource("/resources/right50.png")));
                            break;
                        case 100:
                            voice = java.applet.Applet.newAudioClip(getClass().getResource("/resources/bien.wav"));
                            voice.play();
                            JOptionPane.showMessageDialog(null, "¡Bien Hecho!", "¡Bien Hecho!", JOptionPane.INFORMATION_MESSAGE, new ImageIcon(getClass().getResource("/resources/right100.png")));
                            break;
                        case 200:
                            voice = java.applet.Applet.newAudioClip(getClass().getResource("/resources/bien.wav"));
                            voice.play();
                            JOptionPane.showMessageDialog(null, "¡Bien Hecho!", "¡Bien Hecho!", JOptionPane.INFORMATION_MESSAGE, new ImageIcon(getClass().getResource("/resources/right200.png")));
                            break;
                        case 500:
                            voice = java.applet.Applet.newAudioClip(getClass().getResource("/resources/bien.wav"));
                            voice.play();
                            JOptionPane.showMessageDialog(null, "¡Bien Hecho!", "¡Bien Hecho!", JOptionPane.INFORMATION_MESSAGE, new ImageIcon(getClass().getResource("/resources/right500.png")));
                            break;
                        case 1000:
                            voice = java.applet.Applet.newAudioClip(getClass().getResource("/resources/bien.wav"));
                            voice.play();
                            JOptionPane.showMessageDialog(null, "¡Bien Hecho!", "¡Bien Hecho!", JOptionPane.INFORMATION_MESSAGE, new ImageIcon(getClass().getResource("/resources/right1000.png")));
                            break;
                            
                    }
                            
                    goal = false;
                    
                }else{
                    voice = java.applet.Applet.newAudioClip(getClass().getResource("/resources/mal.wav"));
                  voice.play();
                  JOptionPane.showMessageDialog(null, "Intenta de nuevo", "Intenta de nuevo", JOptionPane.INFORMATION_MESSAGE, new ImageIcon(getClass().getResource("/resources/wrong.png"))); 
                }
                
            }};
        this.addMouseListener(event);
    }
}
